/**
 * @param {View|EmbeddedView} shell
 * @constructor
 */
function SlideShowMediator(shell)
{
	"use strict";

	/** @type {SlideShowMediator} */
	var _this = this;
	/** @type {Number} */
	var _timer = 0;

	this.active = false;

	/**
	 * @return {SlideShowMediator}
	 */
	this.stop = function()
	{
		if (_this.active) {	_this.active = false; }
		return _this.pause();
	};

	/**
	 * @return {SlideShowMediator}
	 */
	this.toggle = function()
	{
		return (_this.active) ? _this.stop() : _this.start(true);
	};

	/**
	 * @return {SlideShowMediator}
	 */
	this.pause = function()
	{
		if (_timer) { window.clearTimeout(_timer); }
		if (shell.toolbar) { shell.toolbar.togglePlay(false).enableNavigation(); }
		return _this;
	};

	/**
	 * @param {Boolean} [immediate = false] Whether to show next image immediately
	 * @return {SlideShowMediator}
	 */
	this.start = function(immediate)
	{
		_this.active = true;
		if (shell.toolbar) { shell.toolbar.togglePlay(true).disableNavigation(); }
		return _this.restart(immediate);
	};

	this.next = function() { };

	/**
	 *  @param {Boolean} [immediate = false] Whether to show next image immediately
	 *  @return {SlideShowMediator}
	 */
	this.restart = function(immediate)
	{
		if (_this.active)
		{
			if (immediate) { _this.next(); }
			_timer = window.setTimeout(_this.next, Enum.duration.slide);
		}
		return _this;
	};
}